package com.flank.weather.ui.place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.flank.weather.logic.Repository
import com.flank.weather.logic.model.PlaceResponse

/**
 * Created by 2021/9/1
 * Email 270554501@qq.com
 * Author Flank
 *
 */
class WeatherViewModel : ViewModel() {

    private val locationLiveData = MutableLiveData<PlaceResponse.Location>()
    var locationLng = ""
    var locationLat = ""
    var placeName = ""
    val weatherLiveData =Transformations.switchMap(locationLiveData){
        location ->
        Repository.refreshWeather(location.lng,location.lat)
    }
    fun refreshWeather(lng:String,lat:String){
        locationLiveData.value= PlaceResponse.Location(lng,lat)
    }
}